/*<!-- saved from url=(0013)about:internet -->*/
//*** Initializations

var education = new Array("None","Highschool Level","Bachelor Level","Master Level","Doctorate Level");

var lang_levels = new Array("Native Level", "Good Level", "Amateur Level");

var field = new Array("Choose field","Software Engineering", "Electrical Engineering", "Biotechnology Engineering","Other");
var trend = new Array("Choose trend","Computers", "Electricity", "Biology", "Other");

var institute = new Array("Choose institution","Braude College","Inferior Technion","Inferior Tel-Aviv Univ.","Other");
var school = new Array("Choose school","Ort Karmim","Ort Megadim","Ort Horowitz");

var jobs = new Array("None", "Software", "Electric", "Biotechnology","Other");

var date = new Date();

var dupRowFlag;
 

function val_from_year() {
	

	var Elem = $("#from_year");
	var currYear = date.getFullYear();
	
	if(isNaN(Elem.val()))	
	{
		alert("Please insert numbers only");
		Elem.val("");
	}
	else if(((Elem.val()<1900) || (Elem.val()>currYear)) && (Elem.val()!="")) 
	{
		alert("Only years between 1900 and "+currYear+" can be inserted");
		Elem.val("");
	}
}

function val_to_year() {
	
	
	var Elem = $("#to_year");
	var currYear = date.getFullYear();
	
	if(isNaN(Elem.val()))	
	{
		alert("Please insert numbers only");
		Elem.val("");
	}
	else if(((Elem.val()<1900) || (Elem.val()>currYear)) && (Elem.val()!="")) 
	{
		alert("Only years between 1900 and "+currYear+" can be inserted");
		Elem.val("");
	}
	
}

 
function findDupRowsInTable(row, tableID){
	
	//row length is # of columns
	var numCols = $('#' + tableID).find('tr')[0].cells.length;

	//Scanning each row
    $('#' + tableID + ' tr').each(function(){
    	var found = 0;
    	var i=0;
    	//Scanning all cells in row
        $(this).children('td').each(function(){
        	if ($(this).html() == row[i])
            {   
            	found++;
            	 i++;  
            	if(found==numCols-1)
            		dupRowFlag=true;
            }
       
        });
    }); 
}





function add_edu() {
	
	var eduBox = document.getElementById("education");
	var eduVal = eduBox.options[eduBox.selectedIndex].text;

	if(eduVal=="None")
		alert("Please select degree/diploma level to add to your education");
	else
	{

		var fieldBox = document.getElementById("edu_field");
		var fieldVal = fieldBox.options[fieldBox.selectedIndex].text;
					
		var instBox = document.getElementById("institute");
		var instVal = instBox.options[instBox.selectedIndex].text;
					
		var row = new Array(eduVal, fieldVal, instVal);
					
		findDupRowsInTable(row,"edutable");
		
		if(dupRowFlag==true) 
		{
			alert("Cannot add the same education twice");
			dupRowFlag=false;
		}
		else 
		{	
			switch(eduVal)
			{
					case "Highschool Level":
					{
						if(fieldVal=="Choose trend") 
							alert("Please select trend to add to your education");
						else if(instVal=="Choose school")
							alert("Please select school to add to your education")
						else
						{
							var remove_btn = '<td> <input type="button" class="btn" value="-"> </td>';
							//$('#edutable tr:last').after('<tr><td>'+eduVal+'</td> <td>'+fieldVal+'</td><td>'+instVal+'</td> </tr>');
							$('<tr><td>'+eduVal+'</td> <td>'+fieldVal+'</td><td>'+instVal+'</td>'+remove_btn+'</tr>').appendTo('#edutable');
							$('#edutable').tableScroll({height:80});
							$('.btn').click(function(){
								var row = $(this).closest('tr');
								row.remove();
							
								var rowCount = $('#edutable tr').length;
							
								if(rowCount==1)
									document.getElementById("div_edutable").style.visibility = "hidden";
							
							});
														  	 										
							document.getElementById("div_edutable").style.visibility = "visible";	
						}						
					}
					break;
					
					default:
					{
						if(fieldVal=="Choose field") 
							alert("Please select trend to add to your education");
						else if(instVal=="Choose institution")
							alert("Please select institution to add to your education")
						else
						{
							var remove_btn = '<td> <input type="button" class="btn" value="-"> </td>';
							//$('#edutable tr:last').after('<tr><td>'+eduVal+'</td> <td>'+fieldVal+'</td><td>'+instVal+'</td> </tr>');
							$('<tr><td>'+eduVal+'</td> <td>'+fieldVal+'</td><td>'+instVal+'</td>'+remove_btn+'</tr>').appendTo('#edutable');
							$('#edutable').tableScroll({height:80});
							$('.btn').click(function(){
								var row = $(this).closest('tr');
								row.remove();
							
								var rowCount = $('#edutable tr').length;
							
								if(rowCount==1)
									document.getElementById("div_edutable").style.visibility = "hidden";
							
							});
							
							document.getElementById("div_edutable").style.visibility = "visible";					  
						}
						
					}
			}
		}
	}
	
}

	

function edu_expand() 
{
	var eduBox = document.getElementById("education");
	var val = eduBox.options[eduBox.selectedIndex].text;
	
	var fieldBox = document.getElementById("edu_field");
	
	var instBox = document.getElementById("institute");
	
	switch(val)
	{
		case "None":
		{
			fieldBox.options.length = 0;
			instBox.options.length = 0;
			document.getElementById("field_expand").style.visibility = "hidden";
			document.getElementById("inst_expand").style.visibility = "hidden";

			
		}
		break;
		
		case "Highschool Level":
		{
			fieldBox.options.length = 0;
			instBox.options.length = 0;
			
		    for(var i=0;i<trend.length; ++i) {
	        	
	            addOption(document.forms["myForm"]["edu_field"], trend[i], trend[i]);
	        }
		    
		    for(var i=0;i<school.length; ++i) {
	        	
	            addOption(document.forms["myForm"]["institute"], school[i], school[i]);
	        }
		    
			document.getElementById("field_expand").style.visibility = "visible";
			document.getElementById("inst_expand").style.visibility = "visible";

			
		}
		break;
		
		case "Bachelor Level":
		{
			fieldBox.options.length = 0;
			instBox.options.length = 0;
			
		    for(var i=0;i<field.length; ++i) {
	        	
	            addOption(document.forms["myForm"]["edu_field"], field[i], field[i]);
	        }
		    
		    for(var i=0;i<institute.length; ++i) {
	        	
	            addOption(document.forms["myForm"]["institute"], institute[i], institute[i]);
	        }
		    
			document.getElementById("field_expand").style.visibility = "visible";
			document.getElementById("inst_expand").style.visibility = "visible";
		}
		break;
		
		case "Master Level":
		{
			fieldBox.options.length = 0;
			instBox.options.length = 0;
			
		    for(var i=0;i<field.length; ++i) {
	        	
	            addOption(document.forms["myForm"]["edu_field"], field[i], field[i]);
	        }
		    
		    for(var i=0;i<institute.length; ++i) {
	        	
	            addOption(document.forms["myForm"]["institute"], institute[i], institute[i]);
	        }
		    
			document.getElementById("field_expand").style.visibility = "visible";
			document.getElementById("inst_expand").style.visibility = "visible";
			
		}
		break;
		
		case "Doctorate Level":
		{
			fieldBox.options.length = 0;
			instBox.options.length = 0;
			
		    for(var i=0;i<field.length; ++i) {
	        	
	            addOption(document.forms["myForm"]["edu_field"], field[i], field[i]);
	        }
		    
		    for(var i=0;i<institute.length; ++i) {
	        	
	            addOption(document.forms["myForm"]["institute"], institute[i], institute[i]);
	        }
		    
			document.getElementById("field_expand").style.visibility = "visible";
			document.getElementById("inst_expand").style.visibility = "visible";
			
		}
		break;
	
	}

}

function add_exp() {
	
	var jobBox = document.getElementById("job_field");
	var jobVal = jobBox.options[jobBox.selectedIndex].text;
	
	if(jobVal=="None")
		alert("Please select degree/diploma level to add to your education");
	else
	{

		var from_year = $('#from_year').val();
		var to_year = $('#to_year').val();
					
		var posBox = document.getElementById("position");
		var posVal = posBox.options[posBox.selectedIndex].text;
					
		var row = new Array(jobVal, from_year, to_year, posVal);
					
		findDupRowsInTable(row,"exptable");
		
		if(dupRowFlag==true) 
		{
			alert("Cannot add the same education twice");
			dupRowFlag=false;
		}
		else
		{
			if((from_year=="") || (to_year==""))
				alert("Please insert 'from' and 'to' years");
			else if(from_year>to_year) 
			{
				alert("The 'from' year cannot be larger than the 'to' year");
			}
			else
			{
				var remove_btn = '<td> <input type="button" class="btn" value="-"> </td>';
				//$('#edutable tr:last').after('<tr><td>'+eduVal+'</td> <td>'+fieldVal+'</td><td>'+instVal+'</td> </tr>');
				$('<tr><td>'+jobVal+'</td> <td>'+from_year+'</td><td>'+to_year+'</td>'+'<td>'+posVal+'</td>'+remove_btn+'</tr>').appendTo('#exptable');
				$('#exptable').tableScroll({height:80});
				$('.btn').click(function(){
					var row = $(this).closest('tr');
					row.remove();
					var rowCount = $('#exptable tr').length;
					
					if(rowCount==1)
						document.getElementById("div_exptable").style.visibility = "hidden";
											  	 
				});
				
				document.getElementById("div_exptable").style.visibility = "visible";
			}
	
		}

	}
}
	



function job_expand() 
{
	var jobBox = document.getElementById("job_field");
	var val = jobBox.options[jobBox.selectedIndex].text;
	
	document.getElementById("position").length = 0;
	
	
	switch(val)
	{
		case "None":
		{
			document.getElementById("from_years_expand").style.visibility = "hidden";
			document.getElementById("to_years_expand").style.visibility = "hidden";
			document.getElementById("pos_expand").style.visibility = "hidden";
			
		}
		break;
		
		case "Other":
		{
			var position = new Array("Accountant", "Advertiser", "Architect","Executive","HR Manager","Real Estate Agent");
			
		    for(var i=0;i<position.length; ++i) {
	        	
	            addOption(document.forms["myForm"]["position"], position[i], position[i]);
	        }

		    document.getElementById("from_years_expand").style.visibility = "visible";
		    document.getElementById("to_years_expand").style.visibility = "visible";
			
			document.getElementById("pos_expand").style.visibility = "visible";
			
		}
		break;
		
		default:
		{
			
			var position = new Array("QA - Student Position","R&D - Student Position","QA Engineer","R&D Engineer","Other");
			
		    
		    for(var i=0;i<position.length; ++i) {
	        	
	            addOption(document.forms["myForm"]["position"], position[i], position[i]);
	        }

		    document.getElementById("from_years_expand").style.visibility = "visible";
		    document.getElementById("to_years_expand").style.visibility = "visible";
			document.getElementById("pos_expand").style.visibility = "visible";
			
		}
		break;

	}
}


//Adds an option to a select box
function addOption(selectbox,text,value)
{
        var optn = document.createElement("OPTION");
        optn.text = text;
        optn.value = value;
        selectbox.options.add(optn);
}

//Initializes all page's display and functional parameters
function init_page() {

		
		//Initializing education combobox values
        for(var i=0; i<education.length; ++i) {
        	
        	addOption(document.forms["myForm"]["education"], education[i], education[i]);
        }
        
        //Initizliaing field combobox values
        for(var i=0; i<jobs.length;++i) {
        	
           	addOption(document.forms["myForm"]["job_field"], jobs[i], jobs[i]);
        }
        
       
        
        //Initializing language levels combobox values
        $("#test > li > select").each(function () {
        	for(var i=0; i<lang_levels.length;++i)
        	{
	        	addOption(this, lang_levels[i], lang_levels[i]);
        	}
        	
        
        });
        
        /*
        //Initializing language levels combobox values
        for(var i=0; i<lang_levels.length;++i) {
        	
           	addOption(document.forms["myForm"]["encombobox"], lang_levels[i], lang_levels[i]);
           	addOption(document.forms["myForm"]["frcombobox"], lang_levels[i], lang_levels[i]);
           	addOption(document.forms["myForm"]["hecombobox"], lang_levels[i], lang_levels[i]);
           	addOption(document.forms["myForm"]["rucombobox"], lang_levels[i], lang_levels[i]);
           	addOption(document.forms["myForm"]["arcombobox"], lang_levels[i], lang_levels[i]);
           	addOption(document.forms["myForm"]["otcombobox"], lang_levels[i], lang_levels[i]); 
        }
        */
        
        
        //Initializing checkboxes' behaviors
        $('#enbox').click(function() {
        	
        	if(this.checked)
        		document.getElementById("encombobox").style.visibility = "visible";
        	else
        		document.getElementById("encombobox").style.visibility = "hidden";	
        });
        
        $('#frbox').click(function() {
        	
        	if(this.checked)
        		document.getElementById("frcombobox").style.visibility = "visible";
        	else
        		document.getElementById("frcombobox").style.visibility = "hidden";
        });
        
        $('#hebox').click(function() {
        	
        	if(this.checked)
        		document.getElementById("hecombobox").style.visibility = "visible";
        	else
        		document.getElementById("hecombobox").style.visibility = "hidden";
        });
        
        $('#rubox').click(function() {
        	
        	if(this.checked)
        		document.getElementById("rucombobox").style.visibility = "visible";
        	else
        		document.getElementById("rucombobox").style.visibility = "hidden"; 	
        });
        
        $('#arbox').click(function() {
        	
        	if(this.checked)
        		document.getElementById("arcombobox").style.visibility = "visible";
        	else
        		document.getElementById("arcombobox").style.visibility = "hidden";
        	
        	
        });
        
        $('#otbox').click(function() {
        	
        	if(this.checked)
        		document.getElementById("otcombobox").style.visibility = "visible";
        	else	
        		document.getElementById("otcombobox").style.visibility = "hidden";    	
        });
        
} 


